package cn.sfrog.project.biz.admin.task;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.sfrog.project.biz.admin.mapper.BizServiceOrderMapper;
import cn.sfrog.project.biz.admin.service.IBizServiceOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

@Component
@Slf4j
@EnableScheduling
public class OrderTask {

    private static final Integer ORDER_OVERTIME_MINUTES = 30;

    @Resource
    private BizServiceOrderMapper bizServiceOrderMapper;
    @Resource
    private IBizServiceOrderService bizServiceOrderService;



    /**
     * 定时更新订单状态 30分钟未支付 就设置为取消
     */
    @Scheduled(cron = "0 0/5 * * * ?")
    public void updateOrderStatus(){
        DateTime dateTime = DateUtil.date();
        bizServiceOrderService.updateServiceOrderStatus(dateTime);
    }

    /**
     * 定时更新订单状态 30分钟未接单 就设置为待服务
     */
    @Scheduled(cron = "0 0/5 * * * ?")
    public void updateOrderAcceptStatus(){
        DateTime dateTime = DateUtil.date();
        bizServiceOrderService.updateServiceOrderAcceptStatus(dateTime);
    }

}
